from functools import wraps as _wraps
from time import time as _time


def timer(show: bool = True):
    """计时器装饰器"""
    def decorate(func):
        @_wraps(func)
        def inner(*args, **kwargs):
            t1 = _time()
            b = func(*args, **kwargs)
            t2 = _time()
            if show:
                print(f"Cost times: {t2-t1:.3f} second.\n")
            return b
        return inner
    return decorate


def times(num: int = 1):
    """多次重复执行"""
    def decorate(func):
        @_wraps(func)
        def inner(*args, **kwargs):
            for _ in range(num):
                b = func(*args, **kwargs)
            return b
        return inner
    return decorate


def output(func):
    """打印函数的输入和输出"""
    @_wraps(func)
    def inner(*args, **kwargs):
        print("Inputs:", *args, **kwargs, sep='\n')
        b = func(*args, **kwargs)
        print("Outputs:", b)
        return b
    return inner


def check(func):
    """检查函数的各项参数是否匹配"""
    @_wraps(func)
    def inner(*args, **kwargs):
        print(func.__annotations__)
        list_anno_values = list(func.__annotations__.values())
        print(list_anno_values)
        for index, para in enumerate(args):
            print(para, list_anno_values[index])
            print(isinstance(para, list_anno_values[index]))
        for k, v in kwargs.items():
            print(v, func.__annotations__[str(k)])
            print(isinstance(v, func.__annotations__[str(k)]))
            ret = func(*args, **kwargs)
        return ret
    return inner
